package com.pig4cloud.pigx.contract.config.schedule;

import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

/**
 * 配置@Scheduled 定时器所使用的线程池
 *
 * @since 2022/9/27 20:33
 */
@Configuration
@AllArgsConstructor
public class TaskScheduleConfig implements SchedulingConfigurer {

	private final TaskScheduler taskScheduler;

	//配置任务注册器：ScheduledTaskRegistrar 的任务调度器
	@Override
	public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
		//可配置两种类型：TaskScheduler、ScheduledExecutorService
		//scheduledTaskRegistrar.setScheduler(taskScheduler());
		//只可配置一种类型：taskScheduler
		scheduledTaskRegistrar.setTaskScheduler(taskScheduler);
	}
}
